home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap03
/
b03d010.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
3KB
|
64 lines
0, You can add a polished look to your
2, applications if you use standard
5, recognizable dialog boxes in your program. Visual
9, Basic provides five ready-made dialog
11, boxes with the CommonDialog ActiveX
13, control. In this demonstration I'll show you
17, how to use the CommonDialog control to
19, create a TextColor dialog box in the
21, menu-driven program that displays the current
24, time and date. First, I'll add a
27, CommonDialog control to the Visual Basic
29, toolbox. I'll click the Project Menu and
32, Components command and click the Controls tab
36, to display the ActiveX controls that
39, are available to my Visual Basic project.
41, I want to add the CommonDialog control,
44, so I'll select it in the Controls tab
46, and click OK. You can see that Visual
50, Basic added the CommonDialog control to my
52, Visual Basic toolbox. And I'll use that
54, now to create a common dialog object on
57, my form. All common dialog objects are
60, the same size, and so Visual Basic resizes
63, it after I create it. And I'm tucking
66, it away down here in an out-of-the-way
67, place in my form. My program is now ready
71, to use the common dialog object. So I'll
73, create a new menu item that changes the
76, text color of the text in the Label1
78, object. I'll click the Menu Editor button.
85, And in the Menu Editor, I'll add the
86, code necessary to create a new TextColor
88, command. I'll go to the bottom of the
90, menu and add an item. Then, I'll give it
95, the name TextColor, pausing to add an
99, access key for the letter "x". And I'll give
102, it the menu item mnu TextColorItem.
110, I'll click OK to add that new command to my
112, menu. And when I click the Clock menu
114, on the form, Visual Basic has added it.
117, When I click TextColor on the form, I
120, have my event procedure in the code window.
123, And I can go ahead and start to write
125, my program code. This event procedure
134, uses the Flags property to create a
136, standard dialog box of color settings, the
139, ShowColor method to display the dialog box,
142, and the FourColor property of the label
144, object to set the common dialog color on
147, our form. Now, we could run this and
152, our time and date program appears in the
154, Visual Basic programming environment as
155, before. When I click the Clock menu, we
159, have our Time, Date, and Text Color
160, commands. The Time command will display the
163, current time, and I can use my new Text
165, Color command to display a Text Color
168, dialog box. I can pick in a cyan, and click
173, OK, and there we go. I have a new cyan
176, text color on my form. So the common
180, dialog object provides many different dialog
182, box types that can be very useful in a
184, program.
186, END